#!/usr/bin/env python3
# -*- coding: utf-8 -*-



'''
Python Base 练习
'''

import re;


print("========== 输入输出 ==========");
# a = input();
# print(a);
print("Hello World!");
print("========== 数据类型 ==========");
a = 11;
print("a 的值是：%s，类型是：%s" % (a, type(a)));
a = 11.11;
print("a 的值是：%s，类型是：%s" % (a, type(a)));
a = True;
print("a 的值是：%s，类型是：%s" % (a, type(a)));
a = 2 + 3j;
print("a 的值是：%s，类型是：%s" % (a, type(a)));
a = "hujiang";
print("a 的值是：%s，类型是：%s" % (a, type(a)));
a = ["cdas", True, None, 22];
print("a 的值是：%s，类型是：%s" % (a, type(a)));
a = ("cdas", True, None, 22);
print("a 的值是：%s，类型是：%s" % (a, type(a)));
a = {"name":"hujiang","age":18};
print("a 的值是：%s，类型是：%s" % (a, type(a)));
a = {"name""age"};
print("a 的值是：%s，类型是：%s" % (a, type(a)));
a = None;
print("a 的值是：%s，类型是：%s" % (a, type(a)));

print("========== 运算符 ==========");
print(5 // 3);
print(True and 5 > 3);

print("========== ASCII 转换 ==========");
print(ord('e'));
print(chr(99));

print("========== 编码转换 ==========");
print("cdsacdas".encode("ASCII"));
print("胡江".encode("utf-8"));
print(b'cdsacdas'.decode("ASCII"));
print(b'\xe8\x83\xa1\xe6\xb1\x9f'.decode("utf-8"));

print("========== 编码转换 ==========");
print(len("胡江"));
print(len("胡江".encode("utf-8")));
print(len("hujiang".encode("utf-8")));

print("========== find 函数 ==========");
print("cdsacasd".find("o"));

print("========== join 函数 ==========");
print("-".join(["I", "love", "my", "country"]));

print("========== 格式化 ==========");
# 我叫胡江，在 02 学期，数学考试成绩为 87.66，成绩增长了 0.12%。
print("我叫%s，在 %02d 学期，数学考试成绩为 %.2f，成绩增长了 %.2f%%。" % ("胡江", 1, 89.456, 0.123));
a = 12;
print(f'我的年龄是{a}');

print("========== 正则表达式 ==========");
# match\search
print(re.match("qqq", "dcdasqqqcdacsacads"));
print(re.search("qqq", "dcdasqqqcdacsacads"));
#验证功能
email_re = "^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$";
if re.match(email_re, "hujiangyx163.com"):
    print("邮箱地址正确");
else:
    print("邮箱地址格式错误");
#分组提取
target = "截止2022-8-28，我省新冠病毒新增12例（海外输入3例），治愈22例，死亡2例，在院观察33例。";
re_pattern = "截止2022-8-28，我省新冠病毒新增(\d+)例（海外输入(\d+)例），治愈(\d+)例，死亡(\d+)例，在院观察(\d+)例。";
result = re.search(re_pattern, target);
if result:
    print(result.groups());
    print(result.group(0));
    print(result.group(1));

temp = '<script defer src="/js/chunk-vendors.js"></script>';
temp_pattern = '<script defer src="(.*?)"></script>';
result = re.search(temp_pattern, temp);
if result:
    print(result.groups());
    print(result.group(0));
    print(result.group(1));

print("========== list ==========");
l = ["cdsaca", 78, 76.22, None, ["cdsa", "dcdas"], 78, True];
print(l);
l = list(range(0, 10));
print(l);
l.append(11);
print(l);
l.insert(0, 12);
print(l);
l.pop();
print(l);
l.pop(0);
print(l);
l.insert(0, 111);
l.remove(0);
print(l);
print(l[0]);
for item in l:
    print(item);
for index, item in enumerate(l):
    print(index, item);

print("========== tuple ==========");
t = ("cdsa", 11, 11, None, False);
print(t);
t = ("cdsa", 11, 11, None, False, ["hj", 111]);
t[5][0] = "hujiang";
print(t);

print("========== dict ==========");
d = {"name":"hujiang", "age":18};
print(d);
d["gender"] = "male";
print(d);
print(d.get("name", "222"));
d.pop("age");
print(d);
d2 = {"aaa":"2323"};
print(dict(d, **d2));

print("========== dict ==========");
s = {"name", "name", "cdascda"};
print(s);
s.add("hj");
print(s);
s.pop();
print(s);
s.remove("cdascda");
print(s);

print("========== 判断 ==========");
age = 20;
if age < 18:
    print("少年");
elif age >= 19 and age <= 60:
    print("壮年");
else:
    print("老年");

print("========== 循环 ==========");
for key in d.keys():
    print(key, d[key]);